<template>
  <view class="hexagram-info">
    <view class="section-title">
      <view class="line"></view>
      <text>卦象信息</text>
    </view>
    
    <view class="hexagram-header">
      <text>{{hexagramData.zhuGua.name}}</text>
      <text v-if="hasBianGua">{{hexagramData.bianGua.name}}</text>
    </view>
    
    <view class="hexagram-content">
      <view class="column-header">
        <text class="col-1">神</text>
        <text class="col-2" v-if="displayOptions.showFuYao">【伏卦】</text>
        <text class="col-3">【主卦】</text>
        <text class="col-4">世应</text>
        <text class="col-5" v-if="hasBianGua">【变卦】</text>
      </view>
      
      <view 
        v-for="(item, index) in hexagramData.zhuGua.yaoList" 
        :key="index"
        class="yao-row"
        :class="{'even': index % 2 === 0}"
      >
        <text class="col-1">{{getLiuShen(index)}}</text>
        <text 
          class="col-2" 
          v-if="displayOptions.showFuYao"
          :class="{'highlight': isFuYaoHighlight(index)}"
        >{{getFuYao(index)}}</text>
        <view class="col-3">
          <text class="yao-symbol" :class="{'active': isYaoActive(index)}">
            {{getYaoSymbol(item.type)}}
          </text>
          <text class="yao-info">{{getYaoInfo(item, index)}}</text>
        </view>
        <text class="col-4">{{hexagramData.zhuGua.shiYing[index]}}</text>
        <view class="col-5" v-if="hasBianGua">
          <text class="yao-symbol">
            {{getYaoSymbol(hexagramData.bianGua.yaoList[index].type)}}
          </text>
          <text class="yao-info">
            {{getYaoInfo(hexagramData.bianGua.yaoList[index], index)}}
          </text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'HexagramInfo',
  
  props: {
    hexagramData: {
      type: Object,
      default: () => ({})
    },
    displayOptions: {
      type: Object,
      default: () => ({})
    }
  },
  
  setup(props) {
    const hasBianGua = computed(() => {
      return props.hexagramData.bianGua?.yaoList?.length > 0
    })
    
    // 获取六神
    const getLiuShen = (index) => {
      // TODO: 实现六神计算
      return ['青龙', '朱雀', '勾陈', '腾蛇', '白虎', '玄武'][index]
    }
    
    // 获取伏神
    const getFuYao = (index) => {
      return props.hexagramData.fuYao[index] || ''
    }
    
    // 判断伏神是否高亮
    const isFuYaoHighlight = (index) => {
      // TODO: 实现伏神高亮逻辑
      return false
    }
    
    // 获取爻符号
    const getYaoSymbol = (type) => {
      return type === 'yin' ? '▅ ▅' : '▅▅▅'
    }
    
    // 判断爻是否活动
    const isYaoActive = (index) => {
      // TODO: 实现动爻判断
      return false
    }
    
    // 获取爻信息
    const getYaoInfo = (yao, index) => {
      if (!yao) return ''
      let info = yao.name || ''
      if (props.displayOptions.showNaYin) {
        info += ' ' + (yao.naYin || '')
      }
      return info
    }
    
    return {
      hasBianGua,
      getLiuShen,
      getFuYao,
      isFuYaoHighlight,
      getYaoSymbol,
      isYaoActive,
      getYaoInfo
    }
  }
}
</script>

<style lang="scss" scoped>
.hexagram-info {
  .section-title {
    // 同 BasicInfo 组件
  }
  
  .hexagram-header {
    display: flex;
    justify-content: space-around;
    margin-bottom: 20rpx;
    font-size: 32rpx;
    font-weight: bold;
  }
  
  .hexagram-content {
    .column-header {
      display: flex;
      padding: 20rpx 0;
      font-size: 28rpx;
      background-color: #f5f5f5;
    }
    
    .yao-row {
      display: flex;
      padding: 20rpx 0;
      font-size: 28rpx;
      
      &.even {
        background-color: #f9f9f9;
      }
    }
    
    .col-1 { flex: 0.3; text-align: center; }
    .col-2 { flex: 0.5; text-align: center; }
    .col-3 { flex: 0.6; display: flex; }
    .col-4 { flex: 0.1; text-align: center; }
    .col-5 { flex: 1; display: flex; }
    
    .yao-symbol {
      margin-right: 10rpx;
      
      &.active {
        color: #f00;
      }
    }
    
    .yao-info {
      flex: 1;
    }
    
    .highlight {
      color: #f00;
      font-weight: bold;
    }
  }
}
</style>